<template>
  <div class="">
    <el-container>
      <el-header class="header">
        <div style="color: rgb(31 41 55);">
          雪梨壁纸管理系统
        </div>
        <div class="user">
          <img src="../../public/avatur.jpg" class="avatur">
          <span class="name">管理员</span>
          <el-button @click="logout" type="danger" size="small">
            <el-icon><CircleClose /></el-icon>
            退出登录
          </el-button>
        </div>
      </el-header>
      <el-container>
        <el-aside class="side">
          <el-menu
          style="border: none;"
          :default-active="activeMenu"
          @select="handleMenuSelect"
        >
          <el-menu-item index="user">
            <el-icon><User /></el-icon>
            <span>用户管理</span>
          </el-menu-item>
          <el-menu-item index="tag">
            <el-icon><Collection /></el-icon>
            <span>标签管理</span>
          </el-menu-item>
          <el-sub-menu index="wallpaper">
            <template #title>
              <el-icon><Picture /></el-icon>
              <span>壁纸管理</span>
            </template>
            <el-menu-item index="wallpaper-operation">壁纸操作</el-menu-item>
            <el-menu-item index="wallpaper-audit">壁纸审核</el-menu-item>
          </el-sub-menu>
          <el-menu-item index="complaint">
            <el-icon><Warning /></el-icon>
            <span>投诉管理</span>
          </el-menu-item>
        </el-menu>
        </el-aside>
        <el-main class="main">
          <el-breadcrumb style="margin-bottom: 1rem;">
          <el-breadcrumb-item>首页</el-breadcrumb-item>
          <el-breadcrumb-item>{{ breadcrumbTitle }}</el-breadcrumb-item>
        </el-breadcrumb>
        <RouterView></RouterView>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script lang="ts" setup>
import {ref,reactive,computed} from 'vue'
import { CircleClose,User,Collection,Picture,Warning} from '@element-plus/icons-vue'
import {useRouter,RouterView} from 'vue-router'
const router=useRouter()
let activeMenu = ref("user");

const breadcrumbTitle = computed(() => {
  const titles= {
    user: "用户管理",
    tag: "标签管理",
    "wallpaper-operation": "壁纸操作",
    "wallpaper-audit": "壁纸审核",
    complaint: "投诉管理",
  };
  return titles[activeMenu.value] || "";
});

function logout(){
  localStorage.removeItem('accessToken')
  localStorage.removeItem('refreshToken')
  router.replace({name:'Login'})
}
function handleMenuSelect(index){
  activeMenu.value = index;
  switch(index){
    case 'user':
      router.push({name:'User'})
      break;
    case 'tag':
      router.push({name:'Tag'})
      break;
    case 'wallpaper-operation':
      router.push({name:'WallpaperOperation'})
      break;
    case 'wallpaper-audit':
      router.push({name:'WallpaperAudit'})
      break;
    case 'complaint':
      router.push({name:'Complaint'})
      break;
  }
}
</script>

<style lang="scss" scoped>
.header{
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: white;
  padding: 0 15px;
  border-bottom:1px solid #eee;

  .user{
    display: flex;
    align-items: center;

    .avatur{
      width: 2rem;
      height: 2rem;
      border-radius: 50%;
      margin-right: 10px;
    }

    .name{
      font-size: 14px;
      color: rgb(75 85 99);
      margin-right: 10px;
    }
  }
}

.side{
  width: 220px;
  background-color: white;
}

.main{
  background-color: #f5f5f5;
  height: calc(100vh - 60px);
  padding: 1.5rem;
}
</style>
